﻿using System;
using System.Text.RegularExpressions;
using NUnit.Framework;
using Birkelund.QueryStrings.Internals;

namespace Birkelund.QueryStrings.Test
{
    public class ArgumentValidationTest
    {
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ThrowIfNullTest_Throw()
        {
            object value = null;
            ArgumentValidation.ThrowIfNull(value, "value");
        }

        [Test]
        public void ThrowIfNullTest_NoThrow()
        {
            ArgumentValidation.ThrowIfNull("myValue", "value");
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ThrowIfNullOrEmptyTest_Throw(
            [Values(
                null,
                "")]
            string value)
        {
            ArgumentValidation.ThrowIfNullOrEmpty(value, "value");
        }

        [Test]
        public void ThrowIfNullOrEmptyTest_NoThrow()
        {
            ArgumentValidation.ThrowIfNullOrEmpty("myValue", "value");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ThrowIfLonger_Throw()
        {
            ArgumentValidation.ThrowIfLonger("exactlyTen", 9, "NA");
        }

        [Test]
        public void ThrowIfLonger_NoThrow()
        {
            ArgumentValidation.ThrowIfLonger("exactlyTen", 10, "NA");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ThrowIfNotMatch_Throw()
        {
            ArgumentValidation.ThrowIfNotMatch("thisIsMyText", new Regex(@"\d"), "NA");
        }

        [Test]
        public void ThrowIfNotMatch_NoThrow()
        {
            ArgumentValidation.ThrowIfNotMatch("1", new Regex(@"\d"), "NA");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ThrowIfEqual_Throw()
        {
            ArgumentValidation.ThrowIfEqual("qwerty", "qwerty", "NA");
        }

        [Test]
        public void ThrowIfEqual_NoThrow()
        {
            ArgumentValidation.ThrowIfEqual("qwerty1", "qwerty2", "NA");
        }
    }
}
